package com.mjlf.ticket.robort;

/**
 * @ClassName RobotSyn
 * @auther mjlf
 * @Date 2019/6/18 19:00
 * @Description TODO
 */
public class RobotSyn {
    public static int num = 0;

    /**
     * 叫号方法
     * @return
     */
    public static int getNum(){
        synchronized (RobotSyn.class){
            return num ++;
        }
    }

    public static void main(String[] args){
        for(int i = 0; i < 10 ; i++){
            new Thread(()->{
                int myNum = getNum();
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("myNum is : " + myNum);
            }).start();
        }

        Thread.yield();
    }
}
